import moment from '../../components/moment.js';
export const getMoney = (data) => {
	let moey = 0.00;
	data.forEach(val => {
		if (!isNaN(val)) {
			moey += val;
		}
	});
	moey = moey.toFixed(2);
	return moey;
};

export const getEnumerate = (parameters, data) => {
	let dataMap = new Map();
	parameters.types.split(",").forEach(val => {
		dataMap.set(val, '');
	})
	data.forEach(val => {
		dataMap.set(val.type, val.items);
	});
	return dataMap;
}

export class timekeeping {
	constructor(beginTime, endTime, surplusSecond) {
		this.beginTime = beginTime;
		this.surplusSecond = surplusSecond ? surplusSecond : 0;
		this.time = '';
		this.date = new Date().getTime();
		this.endTime = endTime ? endTime : 0;
		// this.timekeeping = setInterval(() => {
		// 	// if(this.surplusSecond - 1000 > 0) {
		// 	this.time = '';
		// 	let dates = moment.duration(new Date().getTime() - this.beginTime);
		// 	let hour = dates._data.hours;
		// 	let min = dates._data.minutes;
		// 	let second = dates._data.seconds;
		// 	this.time += dates._data.hours > 0 ? dates._data.hours + '小时' : '';
		// 	this.time += dates._data.minutes > 0 ? dates._data.minutes + '分' : '';
		// 	this.time += dates._data.seconds > 0 ? dates._data.seconds + '秒' : '';
		// 	// this.surplusSecond-= 1000;
		// 	console.log(this.time);
		// 	return this.time;
		// 	// } else {
		// 	// 	clearInterval(this.timekeeping);
		// 	// }
		// }, 1000);
		this.timekeeping2 = function() {
			this.time = '';
			let dates = moment.duration(new Date().getTime() - this.beginTime);
			if(this.endTime) {
				dates = moment.duration(this.endTime - this.beginTime);
			}
			let day = dates._data.days;
			let hour = dates._data.hours;
			let min = dates._data.minutes;
			let second = dates._data.seconds;
			this.time += day > 0 ? day + '天' : '';
			this.time += hour > 0 ? hour + '小时' : '';
			this.time += min > 0 ? min + '分' : '';
			this.time += second > 0 ? second + '秒' : '';
			// console.log(this.time);
			return this.time;
		}
	}
}
